import NProgress from "nprogress"; // progress bar

import usePermission from "@/hooks/permission";
import { useUserStore, useAppStore } from "@/store";
import { WHITE_LIST, NOT_FOUND } from "../constants";

export default function setupPermissionGuard(router) {
  router.beforeEach(async (to, from, next) => {
    const appStore = useAppStore();
    const userStore = useUserStore();
    const Permission = usePermission();
    const permissionsAllow = Permission.accessRouter(to);
    // eslint-disable-next-line no-lonely-if
    if (permissionsAllow) next();
    else {
      const destination = NOT_FOUND;
      // next(destination);
    }
    NProgress.done();
  });
}
